#!/usr/bin/python3
# -*- coding: utf-8 -*-

import numpy  as np
import pandas as pd
import talib as ta

eps = 1e-8

def signal(*args):
    # Ke指标
    df = args[0]
    n = args[1]
    factor_name = args[2]

    volume_avg = df['volume'].rolling(n).mean()
    volume_stander = df['volume'] / volume_avg
    price_change = df['close'].pct_change(n)
    df[factor_name] = (price_change / (abs(price_change) + eps)) * \
        volume_stander * price_change ** 2

    return df
